if ( client == NULL )
{
printk("failed... out of memory\n");
- return NULL;
+ goto fail;
}
memset(client,0,sizeof(client_t));
if ( (client->tmh = tmh_client_init(cli_id)) == NULL )
{
printk("failed... can't allocate host-dependent part of client\n");
- if ( client )
- tmh_free_infra(client);
- return NULL;
+ goto fail;
+ }
+ if ( !tmh_set_client_from_id(client, client->tmh, cli_id) )
+ {
+ printk("failed... can't set client\n");
+ goto fail;
}
- tmh_set_client_from_id(client, client->tmh, cli_id);
client->cli_id = cli_id;
#ifdef __i386__
client->compress = 0;
client->succ_eph_gets = 0; client->succ_pers_gets = 0;
printk("ok\n");
return client;
+
+ fail:
+ tmh_free_infra(client);
+ return NULL;
}
static void client_free(client_t *client)
EXPORT void tmh_client_destroy(tmh_client_t *tmh)
{
+ ASSERT(tmh->domain->is_dying);
#ifndef __i386__
xmem_pool_destroy(tmh->persistent_pool);
#endif
- put_domain(tmh->domain);
tmh->domain = NULL;
}
extern tmh_client_t *tmh_client_init(cli_id_t);
extern void tmh_client_destroy(tmh_client_t *);
-/* we don't need to take a reference to the domain here as we hold
- * one for the entire life of the client, so use rcu_lock_domain_by_id
- * variant instead of get_domain_by_id() */
static inline struct client *tmh_client_from_cli_id(cli_id_t cli_id)
{
struct client *c;
return current->domain;
}
-static inline void tmh_set_client_from_id(struct client *client,
- tmh_client_t *tmh, cli_id_t cli_id)
+static inline bool_t tmh_set_client_from_id(
+ struct client *client, tmh_client_t *tmh, cli_id_t cli_id)
{
- /* here we DO want to take/hold a reference to the domain as
- * this routine should be called exactly once when the client is created;
- * the matching put_domain is in tmh_client_destroy */
- struct domain *d = get_domain_by_id(cli_id);
- d->tmem = client;
- tmh->domain = d;
+ struct domain *d = rcu_lock_domain_by_id(cli_id);
+ bool_t rc = 0;
+ if ( d == NULL )
+ return 0;
+ if ( !d->is_dying )
+ {
+ d->tmem = client;
+ tmh->domain = d;
+ rc = 1;
+ }
+ rcu_unlock_domain(d);
+ return rc;
}
static inline bool_t tmh_current_is_privileged(void)